//
//  BaseView.m
//  HousingPoliceAssistant
//
//  Created by 云警01 on 2019/6/6.
//  Copyright © 2019 盛洋. All rights reserved.
//

#import "BaseView.h"

@interface BaseView ()<TryAgainViewDelegate>
{
    UIAlertView *LG_alertview;
    BOOL is_loading;
    
}
@property (strong, nonatomic) MBProgressHUD *HUD;
@property(strong,nonatomic) TryAgainView *errorView;
@property(strong,nonatomic) NoDataView *NoResult;
@end


@implementation BaseView

-(void)dealloc{
    
    if (_errorView) {
        _errorView = nil;
    }
    
    if (_NoResult) {
        _NoResult = nil;
    }
//    NSLog(@"***********baseView基类的%@ dealloc***********",[NSString stringWithUTF8String:class_getName([self class])]);
}

-(BOOL)isLoadingNow{
    
    return is_loading;
}
//加载动画
-(void)ShowLoading{
    
    is_loading = YES;
    
    self.HUD = [MBProgressHUD showHUDAddedTo:self animated:YES];
    self.HUD.labelText = @"正在加载...";
}

-(void)HideLoading{
    
    is_loading = NO;
    
    if (self.HUD!=nil) {
        self.HUD.delegate = nil;
        [self.HUD removeFromSuperview];
        self.HUD = nil;
    }
    
}

-(void)ShowNewMsg:(NSString*)str
{
    cnhbMsgAlert *alert = [[cnhbMsgAlert alloc] init];
    [alert setTextColor:[UIColor whiteColor]];
    [alert showMessage:str];
}

-(void)LGShowMsg:(NSString*)str {
    [SVProgressHUD showSuccessWithStatus:str];
}

-(void)ShowV3Msg:(NSString *)str
{
    LG_alertview=[[UIAlertView alloc] initWithTitle:@"提示信息" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    LG_alertview.tag = 666666;
    [LG_alertview show];
}

-(void)ShowNoDataView:(UIView *)view Orgin:(CGFloat)Y
{
    if (!_NoResult) {
        NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"NoDataView" owner:self options:nil];
        self.NoResult=[array objectAtIndex:0];
        self.NoResult.frame = CGRectMake(0, Y, view.frame.size.width, view.frame.size.height-Y);
        if ([_NodataStr CheckNSStringData]) {
            self.NoResult.tipLabel.text = _NodataStr;
        }
        [view addSubview:_NoResult];
    }
}
-(void)HideNoDataView
{
    if (_NoResult) {
        [_NoResult removeFromSuperview];
        self.NoResult=nil;
    }
}
-(void)ShowerrorView:(UIView *)view Orgin:(CGFloat)Y
{
    if (_errorView == nil) {
        _errorView  = [[[NSBundle mainBundle] loadNibNamed:xibNameTryAgain owner:self options:nil]lastObject];
        _errorView.frame = CGRectMake(0, Y, view.frame.size.width, view.frame.size.height-Y);
        _errorView.backgroundColor = [UIColor whiteColor];
        [_errorView loadingError];
        _errorView.delegate = self;
    }
    [view addSubview:_errorView];
}
-(void)HideerrorView
{
    if (_errorView) {
        [_errorView removeFromSuperview];
        self.errorView=nil;
    }
}

-(void)ScreenBtnClicked
{
    [self HideNoDataView];
    [self HideerrorView];
}


@end
